<?php

namespace Common\Model;

use Think\Model;

/**
 * Description of UserModel
 *
 * @author Shangyidong
 */
class ImageModel extends Model {

    function get($id) {
        if ($id == null) {
            return null;
        }
        $ImageModel = new \Common\Model\ImageModel();
        $image = $ImageModel->where("id = " . $id)->find();
        return $image;
    }

    /**
     * 根据图片的id删除图片
     * @param type $id
     * @return null
     */
    function delete_image($id) {
        if ($id == null) {
            return null;
        }
        $ImageModel = new \Common\Model\ImageModel();
        $image = $ImageModel->where("id = " . $id)->find();
        if ($image == null) {
            return;
        }
        if (!unlink($image['img_url'])) {//从磁盘删除图片文件
            /*
              $this->on_error('Can\'t delete file!', 309); //出错处理
              echo '不能删除旧文件';
              exit;
             */
        }
        $ImageModel->where("id = " . $id)->delete();//从数据库中删除图片
    }

}
